﻿using System;

namespace Fabrication
{
    internal static class RandomNumberGenerator
    {
        private static readonly Random random = new Random();

        public static int GetInteger(int minimum, int maximum)
        {
            return random.Next(minimum, maximum + 1);
        }

        public static long GetLong(long minimum, long maximum)
        {
            var bytes = new byte[8];
            random.NextBytes(bytes);
            bytes[7] = (byte)(bytes[7] & 0x7f);

            var nonNegativeLong = BitConverter.ToInt64(bytes, 0);
            var range = maximum - minimum;
            var nextLong = (long)((nonNegativeLong / (double)Int64.MaxValue) * range);
            return nextLong + minimum;
        }

        public static float GetFloat(float minimum, float maximum)
        {
            return minimum + Convert.ToSingle(random.NextDouble() * (maximum - minimum));
        }

        public static double GetDouble(double minimum, double maximum)
        {
            return minimum + random.NextDouble() * (maximum - minimum);
        }

        public static decimal GetDecimal(decimal minimum, decimal maximum)
        {
            return minimum + (Convert.ToDecimal(random.NextDouble())*(maximum - minimum));
        }
    }
}